/*
 *
 *  * Copyright (C) 2014 Antonio Leiva Gordillo.
 *  *
 *  * Licensed under the Apache License, Version 2.0 (the "License");
 *  * you may not use this file except in compliance with the License.
 *  * You may obtain a copy of the License at
 *  *
 *  *      http://www.apache.org/licenses/LICENSE-2.0
 *  *
 *  * Unless required by applicable law or agreed to in writing, software
 *  * distributed under the License is distributed on an "AS IS" BASIS,
 *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  * See the License for the specific language governing permissions and
 *  * limitations under the License.
 *
 */

package tw.asap.plus.presenter;


import tw.asap.plus.utils.SPUtil;


public class LogoutPresenterImpl implements LogoutPresenter, OnFinishedListener {

    private LogoutView logoutView;

    private SPUtil spUtil;

    public LogoutPresenterImpl(LogoutView logoutView) {
        this.logoutView = logoutView;
        spUtil = SPUtil.getInstance(logoutView.getContext());
    }

    @Override
    public void logout() {
        logoutView.showProgress();
        logoutNow();
    }



    @Override
    public void onSuccess() {
        logoutView.onSuccess();
    }

    @Override
    public void onFailed(String resperr) {
        logoutView.onFailed(resperr);
    }

    private void logoutNow(){
//        NormalStringRequest request = new NormalStringRequest(logoutView.getContext(), Request.Method.POST, ConstValue.LOGOUT_API_URL, responselistener, responselistener);
//        VolleyController.getInstance().addToRequestQueue(request);
    }



//    NormalStringResponseListener responselistener = new NormalStringResponseListener() {
//        @Override
//        public void onResponse(String response) {
//            super.onResponse(response);
//            JSONObject object;
//            try {
//                object = new JSONObject(response);
//                if (object.getString("respcd").equals(ConstValue.RESPCD)) {
//                    //成功
//                    // TODO
//                    spUtil.save(ConstValue.Sp.PASSWORD, "");
//                    spUtil.save(ConstValue.Sp.COOKIE, "");
//                    onSuccess();
//
//                } else {
//                    String resperr = object.getString("resperr");
//                    onFailed(resperr);
//                }
//
//            } catch (JSONException e) {
//                e.printStackTrace();
//                spUtil.save(ConstValue.Sp.PASSWORD, "");
//                spUtil.save(ConstValue.Sp.COOKIE, "");
//                onFailed("");
//            }
//        }
//
//        @Override
//        public void onErrorResponse(VolleyError error) {
//            super.onErrorResponse(error);
//            spUtil.save(ConstValue.Sp.PASSWORD, "");
//            spUtil.save(ConstValue.Sp.COOKIE, "");
//            onFailed("");
//        }
//    };



}
